package com.headFirstModel.observerPattern.jdk;

import com.headFirstModel.observerPattern.custom.DisplayElement;

import java.util.Observable;
import java.util.Observer;

public class ForecastDisplay implements Observer, DisplayElement {
    private float currentPressure = 29.92f ;
    private float lastPressure;

    public ForecastDisplay(Observable observable) {
        observable .addObserver ( this );
    }

    @Override
    public void display() {
        // 这里显示代码
        System.out.println("上一次温度:"+lastPressure+"，现在温度:"+currentPressure);
    }

    @Override
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData )observable;
            lastPressure =currentPressure;
            currentPressure = weatherData.getPressure ( ) ;
        }
        display( );
    }
}
